package com.credithc.customers.api.controller;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.customers.api.service.ICustomerCreditService;
import com.credithc.customers.base.ro.UnifyCreditRo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 页面跳转相关接口-百朗--小恒钱包
 * @author: denghx
 * @date: 2020/5/8 18:29
 * @param: null
 * @return:
 */
@RestController
@RequestMapping("/api/yzt/v1/unify/channel")
@Slf4j
public class CustomerCreditController {
    @Autowired
    ICustomerCreditService customerCreditService;
    @Autowired
    MessageFactory messageFactory;

    /**
     * @description: 查询页面是否跳转授信
     * @author: denghx
     * @date: 2020/5/11 14:10
     * @param: ro
     * @return: org.springframework.http.ResponseEntity
     */
    @PostMapping(value = "/getCredit")
    public Message getCredit(@RequestBody UnifyCreditRo ro) {
        String redirectUrl = customerCreditService.getCredit(ro);
        Map<String, Object> map = new HashMap<>();
        map.put("redirectUrl",redirectUrl);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        //response.sendRedirect(redirectUrl);
    }

    @PostMapping(value = "/credit")
    public Message credit(@RequestBody UnifyCreditRo ro) {
        String redirectUrl = customerCreditService.credit(ro);
        Map<String, Object> map = new HashMap<>();
        map.put("redirectUrl",redirectUrl);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
        //response.sendRedirect(redirectUrl);
//        return ResponseEntity.status(HttpStatus.MOVED_PERMANENTLY).header(HttpHeaders.LOCATION, redirectUrl).build();
    }

}